package com.ljkj.cordial.chat.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanjiu.lib.imclient.ims.IMSContacts;
import com.ljkj.cordial.chat.R;
import com.ljkj.cordial.chat.bean.GroupSimpleBean;
import com.ljkj.cordial.chat.widget.PuzzleImageView;
import com.nic.view.adapter.CommonAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TransmitGroupAdapter extends CommonAdapter<GroupSimpleBean> {
    @Override
    public View getBindView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_nav_group, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        GroupSimpleBean item = (GroupSimpleBean) getItem(position);
        holder.tvTitle.setText(item.getGroupName());
        if (!TextUtils.isEmpty(item.getMemberAvatarUrls()) && !TextUtils.isEmpty(item.getMemberUserIds())) {
            holder.piv.setImageBackGround(item.getMemberAvatarUrls(), item.getMemberUserIds());
        } else {
            holder.piv.setImageResource(R.mipmap.pic_group_avatar_default_70dp);
        }
        if (IMSContacts.UserType.TOURISTS_USER.equals(item.getGroupType())) {
            holder.ivIsVisitor.setVisibility(View.VISIBLE);
        } else {
            holder.ivIsVisitor.setVisibility(View.GONE);
        }
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.piv)
        PuzzleImageView piv;
        @BindView(R.id.iv_is_visitor)
        ImageView ivIsVisitor;
        @BindView(R.id.tv_title)
        TextView tvTitle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
